var t = require;
var e = module;
var o = exports;
Object.defineProperty(o, "__esModule", {value: !0});
var n = (function () {
    function t() {
        this.times = 0;
    }
    return (
        (t.prototype.init2 = function (t) {
            for (var e in ((this.key = t),
            (this.keys = []),
            (this.dirty = !1),
            (this.defaultValues = {}),
            (this.values = {}),
            this))
                switch (e) {
                    case "key":
                    case "keys":
                    case "dirty":
                    case "defaultValues":
                    case "values":
                        break;
                    default:
                        switch (typeof this[e]) {
                            case "boolean":
                            case "number":
                            case "string":
                                this.keys.push(e), (this.defaultValues[e] = this[e]);
                                break;
                            case "object":
                                this.keys.push(e), (this.defaultValues[e] = JSON.parse(JSON.stringify(this[e])));
                        }
                }
            var o;
            try {
                o = localStorage.getItem(this.key);
            } catch (t) {
                console.error("e=" + t), (o = "");
            }
            if (o && (o = o.replace(/^\s*|\s*$/g, ""))) {
                var n = void 0;
                try {
                    n = JSON.parse(o);
                } catch (t) {
                    n = null;
                }
                if (n) for (var e in n) this[e] = n[e];
            }
        }),
        (t.prototype.reset = function () {
            for (var t = 0, e = this.keys; t < e.length; t++) {
                var o = e[t];
                switch (typeof this.defaultValues[o]) {
                    case "boolean":
                    case "number":
                    case "string":
                        this[o] = this.defaultValues[o];
                        break;
                    case "object":
                        this[o] = JSON.parse(JSON.stringify(this.defaultValues[o]));
                }
            }
        }),
        (t.prototype.update = function (t) {
            if (t.times > this.times) for (var e in t) this[e] = t[e];
        }),
        (t.prototype.toJSONCode = function () {
            for (var t = 0, e = this.keys; t < e.length; t++) {
                var o = e[t];
                this.values[o] = this[o];
            }
            return JSON.stringify(this.values, null, "\t");
        }),
        (t.prototype.setDirty = function () {
            this.dirty = !0;
        }),
        (t.prototype.write = function () {
            if (this.dirty) {
                (this.dirty = !1), this.times++;
                var t = this.toJSONCode();
                try {
                    localStorage.setItem(this.key, t);
                } catch (t) {
                    console.error("e=" + t);
                }
            }
        }),
        t
    );
})();
o.default = n;
